<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分享页</title>
    <link rel="icon" href="/image/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="css/sharePage.css">
</head>
<body>
<div class="all">
   <div id="main">
       <img src="image/background1.jpg" alt="" id="background">
       <div id="main_logo"><img src="image/logo.png" alt=""></div>
       <div id="share">
           <div id="share_head">
               <ul>
                   <li><img src="https://ss0.bdstatic.com/7Ls0a8Sm1A5BphGlnYG/sys/portrait/item/ea9cba66.jpg" alt="" id="user_photo"></li>
                   <li><p><span id="user_name"></span>&nbsp;&nbsp;&nbsp;给你分享了文件</p></li>
               </ul>
           </div>
           <dt>请输入提取码：</dt>
           <div id="input">
               <input type="text" name="share" id="share_password">
               <input type="button" name="button" value="提取文件" id="share_button">
           </div>
       </div>
   </div>
    <iframe src="footer.html" frameborder="0" scrolling="no" class="iframe"></iframe>
</div>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.2.2/jquery.js"></script>
<script>

    //通过分享码查找分享信息
    window.onload = function () {
        var url = window.location.href;
        var urls = new Array();
        urls = url.split('=');
        var shareId = urls[1];
        $.ajax({
            url:'/pan/shareById',
            type:'post',
            data:{shareId: shareId},
            success:function(data){  //请求成功后的回调函数，其中的参数data为controller返回的map,也就是说,@ResponseBody将返回的map转化为JSON格式的数据，然后通过data这个参数取JSON数据中的值
                var sharePassword = data.data.sharePassword;   //获取提取码
                var name = data.data.name;                  //获取用户名
                $('#user_name').html(name);
                var userPhoto =data.data.photo;
                var photo = document.getElementById("user_photo");   //获取用户头像
                photo.setAttribute("src",userPhoto);
                if(sharePassword==null){                   //判断是否有提取码
                    $('#share_password').attr('disabled',"disabled")
                }
            },error:function(err){
                console.log(err);
            }
        });

        //提交验证码
        $('#share_button').click(function () {
            var url = window.location.href;
            var urls = new Array();
            urls = url.split('=');
            var shareId = urls[1];
            $.ajax({
                url:'/pan/judgeShareCode',
                type:'post',
                data:{sharePassword: $('#share_password').val(),shareId:shareId},
                success:function(data){  //请求成功后的回调函数，其中的参数data为controller返回的map,也就是说,@ResponseBody将返回的map转化为JSON格式的数据，然后通过data这个参数取JSON数据中的值
                    if(data.message == "success"){
                        $.ajax({
                            url:'/pan/findShareId',
                            data:{shareId:shareId},
                            type:'post',
                            success:function (e) {
                                if(data.message=='success'){
                                    var  userFileId = e.data;
                                    window.location.href = 'shareExtract.html?userFileId='+ userFileId+'&&shareId='+shareId;
                                }else if(data.message=='fails'){
                                    alert("查询失败");
                                }
                            }
                        });
                    }
                },error:function(err){
                    console.log(err);
                }
            })
        })
    }
</script>
</body>
</html>